/*
 * Created by JFormDesigner on Thu Dec 23 12:30:19 CST 2021
 */

package com.cn.项目.飞机预约管理系统.Maininterface;

import com.cn.项目.utils.JdbcUtils;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author Brainrain
 */
public class CancelReservation extends JFrame {

    public CancelReservation() {
        initComponents();
    }
    String date = null;
    String start = null;
    String endlo = null;
    String na = null;  //代买人
    String money = null; //金额

    //取消预约
    private void button1ActionPerformed(ActionEvent e) {
        // TODO add your code here
        na= textField1.getText();
        money = textField2.getText();
        String state = textField3.getText();
        Connection conn = null;
        PreparedStatement st = null;
        PreparedStatement st1 = null;
        ResultSet rs = null;
        int m =  Integer.parseInt(money);
        try {
          conn =   JdbcUtils.getConnection();
          String sql = "update  users set money=money+? where uname=?";
          st  = conn.prepareStatement(sql);
          st.setInt(1, m);
          st.setString(2,na );
            int i = st.executeUpdate();
            if (i>0){
                new Success();
            }else {
                new Fail();
            }

            String sql01="DELETE FROM `booktickets` WHERE `bstart`=?and `bend`=?and`bdate`=?and`bname`=?and state=?";
            st1 =  conn.prepareStatement(sql01);
            st1.setString(1,start );
            st1.setString(2,endlo );
            st1.setString(3,date );
            st1.setString(4,na);
            st1.setString(5,state );
            st1.executeUpdate();
        } catch (SQLException e1) {
            e1.printStackTrace();
        }
    }

    //日期
    private void comboBox1ActionPerformed(ActionEvent e) {
        // TODO add your code here
        date = comboBox1.getSelectedItem().toString();
    }

    //出发地
    private void comboBox2ActionPerformed(ActionEvent e) {
        // TODO add your code here
        start = comboBox2.getSelectedItem().toString();
    }

    //目的地
    private void comboBox3ActionPerformed(ActionEvent e) {
        // TODO add your code here
        endlo = comboBox3.getSelectedItem().toString();

    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        label1 = new JLabel();
        label2 = new JLabel();
        label3 = new JLabel();
        label4 = new JLabel();
        label5 = new JLabel();
        label6 = new JLabel();
        button1 = new JButton();
        comboBox1 = new JComboBox();
        comboBox2 = new JComboBox();
        comboBox3 = new JComboBox();
        textField1 = new JTextField();
        textField2 = new JTextField();
        label7 = new JLabel();
        textField3 = new JTextField();

        //======== this ========
        setVisible(true);
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- label1 ----
        label1.setText("\u9000\u6b3e");
        label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 12f));
        contentPane.add(label1);
        label1.setBounds(135, 5, 160, 40);

        //---- label2 ----
        label2.setText("\u65e5\u671f\uff1a");
        label2.setFont(label2.getFont().deriveFont(label2.getFont().getSize() + 6f));
        contentPane.add(label2);
        label2.setBounds(15, 60, 95, 35);

        //---- label3 ----
        label3.setText("\u51fa\u53d1\u5730\uff1a");
        label3.setFont(label3.getFont().deriveFont(label3.getFont().getSize() + 6f));
        contentPane.add(label3);
        label3.setBounds(15, 105, 95, 35);

        //---- label4 ----
        label4.setText("\u76ee\u7684\u5730\uff1a");
        label4.setFont(label4.getFont().deriveFont(label4.getFont().getSize() + 6f));
        contentPane.add(label4);
        label4.setBounds(15, 150, 95, 35);

        //---- label5 ----
        label5.setText("\u4ee3\u4e70\u4eba\uff1a");
        label5.setFont(label5.getFont().deriveFont(label5.getFont().getSize() + 6f));
        contentPane.add(label5);
        label5.setBounds(15, 195, 95, 35);

        //---- label6 ----
        label6.setText("\u91d1\u989d\uff1a");
        label6.setFont(label6.getFont().deriveFont(label6.getFont().getSize() + 6f));
        contentPane.add(label6);
        label6.setBounds(15, 235, 95, 35);

        //---- button1 ----
        button1.setText("\u9000\u6b3e");
        button1.setFont(button1.getFont().deriveFont(button1.getFont().getSize() + 6f));
        button1.addActionListener(e -> button1ActionPerformed(e));
        contentPane.add(button1);
        button1.setBounds(135, 340, 105, 35);

        //---- comboBox1 ----
        comboBox1.addActionListener(e -> comboBox1ActionPerformed(e));
        contentPane.add(comboBox1);
        comboBox1.setBounds(120, 60, 140, 35);

        //---- comboBox2 ----
        comboBox2.addActionListener(e -> comboBox2ActionPerformed(e));
        contentPane.add(comboBox2);
        comboBox2.setBounds(120, 105, 140, 35);

        //---- comboBox3 ----
        comboBox3.addActionListener(e -> comboBox3ActionPerformed(e));
        contentPane.add(comboBox3);
        comboBox3.setBounds(120, 150, 140, 35);
        contentPane.add(textField1);
        textField1.setBounds(120, 200, 130, 35);
        contentPane.add(textField2);
        textField2.setBounds(120, 240, 130, 35);

        //---- label7 ----
        label7.setText("\u72b6\u6001\uff1a");
        label7.setFont(label7.getFont().deriveFont(label7.getFont().getSize() + 6f));
        contentPane.add(label7);
        label7.setBounds(15, 290, 60, 30);

        //---- textField3 ----
        textField3.setText("\u53d6\u6d88");
        contentPane.add(textField3);
        textField3.setBounds(120, 290, 130, 35);

        contentPane.setPreferredSize(new Dimension(400, 415));
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
        comboBox1.addItem("2021-12-13");
        comboBox1.addItem("2021-12-14");
        comboBox1.addItem("2021-12-15");
        comboBox1.addItem("2021-12-16");
        comboBox1.addItem("2021-12-17");
        comboBox1.addItem("2021-12-18");
        comboBox1.addItem("2021-12-19");
        comboBox1.addItem("2021-12-20");

        comboBox2.addItem("上海");
        comboBox2.addItem("北京");
        comboBox2.addItem("广州");
        comboBox2.addItem("深圳");

        comboBox3.addItem("上海");
        comboBox3.addItem("洛杉矶");
        comboBox3.addItem("香港");
        comboBox3.addItem("濮阳");
        comboBox3.addItem("北京");
        comboBox3.addItem("澳门");



    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JLabel label1;
    private JLabel label2;
    private JLabel label3;
    private JLabel label4;
    private JLabel label5;
    private JLabel label6;
    private JButton button1;
    private JComboBox comboBox1;
    private JComboBox comboBox2;
    private JComboBox comboBox3;
    private JTextField textField1;
    private JTextField textField2;
    private JLabel label7;
    private JTextField textField3;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
